<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="fyhAdditionPro"
      :columns="columns"
      height="auto"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { addItem, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';

export default {
  name: 'additionalPro',
  components: {},
  mixins: [dictionary],
  props: ['dataList', 'roNo'],
  data() {
    return {
      columns: this.createTableColumns(),
      list: [],
      fetchApi: addItem,
      fetchParams: {}
    };
  },
  created() {
    let roNo = this.roNo;
    this.fetchParams = Object.assign({}, { roNo: roNo }, { xhrAbort: false });
  },
  mounted() {
    // this.queryAdditionaItem();
    this.queryChargeList();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          minWidth: 100,
          sorter: true,
          showOverflowTooltip: true,
          editable: false,
          defaultEditable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '附加项目代码',
          dataIndex: 'ADD_ITEM_CODE',
          minWidth: 120,
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '附加项目名称',
          dataIndex: 'ADD_ITEM_NAME',
          minWidth: 120,
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          minWidth: 110,
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          minWidth: 100,
          sorter: true,
          showOverflowTooltip: true,
          numberFormat: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          minWidth: 90,
          sorter: true,
          showOverflowTooltip: true,
          editable: false,
          defaultEditable: true,
          editType: 'input'
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          minWidth: 100,
          sorter: true,
          showOverflowTooltip: true,
          numberFormat: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          minWidth: 170,
          sorter: true,
          showOverflowTooltip: true,
          editable: false,
          defaultEditable: false,
          editType: 'input'
        }
      ];
    },

    // 清空列表
    changeempty() {
      if (this.empty) {
        this.list = [];
        this.$emit('changeEmpty', false);
      }
      return;
    },

    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },

    // 附加材料查询
    async queryAdditionaItem() {
      const roNo = this.roNo;
      const res = (await addItem(roNo)).data.rows;
      this.list = res;
    }
  }
};
</script>

<style lang="less"></style>
